package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.WorkflowBusiness;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2021-02-24 16:00:17
 */
@Repository
public class WorkflowBusinessDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(WorkflowBusinessDao.class);

    public WorkflowBusiness insert(final WorkflowBusiness workflowBusiness) {
        insert("WorkflowBusiness.insert", workflowBusiness);
        return workflowBusiness;
    }

    public Boolean updateInfoById(final WorkflowBusiness workflowBusiness) {
        return update("WorkflowBusiness.updateInfoById", workflowBusiness) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("WorkflowBusiness.updateInfoByQuery", query) > 0;
    }

    public WorkflowBusiness selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("WorkflowBusiness.selectById", query);
    }

    public List<WorkflowBusiness> selectByQuery(final Query query) {
        return queryForList("WorkflowBusiness.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("WorkflowBusiness.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        WorkflowBusiness workflowBusiness = new WorkflowBusiness();
        workflowBusiness.setDeleteFlag(1);
        workflowBusiness.setId(id);
        workflowBusiness.setEntId(entId);

        return update("WorkflowBusiness.updateInfoById", workflowBusiness) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("WorkflowBusiness.deleteById", query) > 0;
    }
}